using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace AppManagement.Repositories
{
	#region using
	using AppManagement.Models;
	#endregion
	public class PhieuKham_ThuocRepository
	{
		public static List<PhieuKham_Thuoc> SelectAll()
		{
			return DataContext.Instance.PhieuKham_Thuoc.ToList();
		}

		public static PhieuKham_Thuoc SelectByID(int mapkthuoc)
		{
			return DataContext.Instance.PhieuKham_Thuoc.FirstOrDefault(item => item.MaPKThuoc == mapkthuoc );
		}

		public static bool Insert(PhieuKham_Thuoc obj)
		{
			try
			{
				DataContext.Instance.PhieuKham_Thuoc.AddObject(obj);
				DataContext.Instance.SaveChanges();
				return true;
			}
			catch
			{
				return false;
			}
		}

		public static bool Delete(int mapkthuoc)
		{
			try
			{
				var delitem = DataContext.Instance.PhieuKham_Thuoc.FirstOrDefault(item => item.MaPKThuoc == mapkthuoc );
				DataContext.Instance.PhieuKham_Thuoc.DeleteObject(delitem);
				DataContext.Instance.SaveChanges();
				return true;
			}
			catch
			{
				return false;
			}
		}

		public static bool Save()
		{
			try
			{
				DataContext.Instance.SaveChanges();
				return true;
			}
			catch
			{
				return false;
			}
		}

		public static List<PhieuKham_Thuoc> RetrieveByID(int mapkthuoc)
		{
			return (from item in DataContext.Instance.PhieuKham_Thuoc where  item.MaPKThuoc == mapkthuoc  select item).ToList();
		}

		public static List<PhieuKham_Thuoc> SelectByMaPK(string mapk)
		{
			var lstItem = (from item in DataContext.Instance.PhieuKham_Thuoc where item.MaPK == mapk select item).ToList();
			return lstItem;
		}

		public static List<PhieuKham_Thuoc> SelectByMaThuoc(string mathuoc)
		{
			var lstItem = (from item in DataContext.Instance.PhieuKham_Thuoc where item.MaThuoc == mathuoc select item).ToList();
			return lstItem;
		}
	}
}